home *** CD-ROM | disk | FTP | other *** search
/ Night Owl 6 / Night Owl's Shareware - PDSI-006 - Night Owl Corp (1990).iso / 039a / dflat8.zip / RECT.C < prev    next >
Text File  |  1991-09-06  |  3KB  |  95 lines

  1. /* ------------- rect.c --------------- */
  2.  
  3. #include "dflat.h"
  4.  
  5.  /* --- Produce the vector end points produced by the overlap
  6.         of two other vectors --- */
  7. static void subVector(int *v1, int *v2,
  8.                         int t1, int t2, int o1, int o2)
  9. {
  10.     *v1 = *v2 = -1;
  11.     if (within(o1, t1, t2))    {
  12.         *v1 = o1;
  13.         if (within(o2, t1, t2))
  14.             *v2 = o2;
  15.         else
  16.             *v2 = t2;
  17.     }
  18.     else if (within(o2, t1, t2))    {
  19.         *v2 = o2;
  20.         if (within(o1, t1, t2))
  21.             *v1 = o1;
  22.         else
  23.             *v1 = t1;
  24.     }
  25.     else if (within(t1, o1, o2))    {
  26.         *v1 = t1;
  27.         if (within(t2, o1, o2))
  28.             *v2 = t2;
  29.         else
  30.             *v2 = o2;
  31.     }
  32.     else if (within(t2, o1, o2))    {
  33.         *v2 = t2;
  34.         if (within(t1, o1, o2))
  35.             *v1 = t1;
  36.         else
  37.             *v1 = o1;
  38.     }
  39. }
  40.  
  41.  /* --- Return the rectangle produced by the overlap
  42.         of two other rectangles ---- */
  43. RECT subRectangle(RECT r1, RECT r2)
  44. {
  45.     RECT r = {0,0,0,0};
  46.     subVector((int *) &RectLeft(r), (int *) &RectRight(r),
  47.         RectLeft(r1), RectRight(r1),
  48.         RectLeft(r2), RectRight(r2));
  49.     subVector((int *) &RectTop(r), (int *) &RectBottom(r),
  50.         RectTop(r1), RectBottom(r1),
  51.         RectTop(r2), RectBottom(r2));
  52.     if (RectRight(r) == -1 || RectTop(r) == -1)
  53.         RectRight(r) =
  54.         RectLeft(r) =
  55.         RectTop(r) =
  56.         RectBottom(r) = 0;
  57.     return r;
  58. }
  59.  
  60. /* ------- return the client rectangle of a window ------ */
  61. RECT ClientRect(void *wnd)
  62. {
  63.     RECT rc;
  64.  
  65.     RectLeft(rc) = GetClientLeft((WINDOW)wnd);
  66.     RectTop(rc) = GetClientTop((WINDOW)wnd);
  67.     RectRight(rc) = GetClientRight((WINDOW)wnd);
  68.     RectBottom(rc) = GetClientBottom((WINDOW)wnd);
  69.     return rc;
  70. }
  71.  
  72. /* ----- return the rectangle relative to
  73.             its window's screen position -------- */
  74. RECT RelativeWindowRect(void *wnd, RECT rc)
  75. {
  76.     RectLeft(rc) -= GetLeft((WINDOW)wnd);
  77.     RectRight(rc) -= GetLeft((WINDOW)wnd);
  78.     RectTop(rc) -= GetTop((WINDOW)wnd);
  79.     RectBottom(rc) -= GetTop((WINDOW)wnd);
  80.     return rc;
  81. }
  82.  
  83. /* ----- clip a rectangle to the parents of the window ----- */
  84. RECT ClipRectangle(void *wnd, RECT rc)
  85. {
  86.     RECT sr;
  87.     RectLeft(sr) = RectTop(sr) = 0;
  88.     RectRight(sr) = SCREENWIDTH-1;
  89.     RectBottom(sr) = SCREENHEIGHT-1;
  90.     if (!TestAttribute((WINDOW)wnd, NOCLIP))
  91.         while ((wnd = GetParent((WINDOW)wnd)) != NULL)
  92.             rc = subRectangle(rc, ClientRect(wnd));
  93.     return subRectangle(rc, sr);
  94. }
  95.